package com.example.innovate.service.impl;

import com.example.innovate.domain.PositionInfoDO;
import com.example.innovate.domain.PositionInfoDOExample;
import com.example.innovate.mapper.PositionInfoDOMapper;
import com.example.innovate.service.PositionService;
import com.github.pagehelper.PageHelper;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PositionServiceImpl implements PositionService {
    @Autowired
    PositionInfoDOMapper positionInfoDOMapper;

    @Override
    public PositionInfoDO addInfo(PositionInfoDO positionInfoDO) {
        positionInfoDOMapper.insertSelective(positionInfoDO);
        return positionInfoDO;
    }

    @Override
    public void deleteInfo(int id) {
        positionInfoDOMapper.deleteByPrimaryKey(id);
    }

    @Override
    public PositionInfoDO updateInfo(PositionInfoDO positionInfoDO) {
        positionInfoDOMapper.updateByPrimaryKeySelective(positionInfoDO);
        return positionInfoDO;
    }

    @Override
    public PositionInfoDO findById(int id) {
        return positionInfoDOMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<PositionInfoDO> findInfo(String corporate, String position,
                                         String address, double payStart,double payEnd, Integer pageNumber, Integer pageSize) {
        PositionInfoDOExample positionInfoDOExample = new PositionInfoDOExample();
        PositionInfoDOExample.Criteria criteria = positionInfoDOExample.createCriteria();
        PageHelper.startPage(pageNumber,pageSize);
        if (!StringUtils.isEmpty(corporate)) {
            criteria.andPoCorporateEqualTo(corporate);
        }
        if (!StringUtils.isEmpty(position)) {
            criteria.andPoPositionEqualTo(position);
        }
        if (payStart!=0&&payEnd!=0){
            criteria.andPoPayBetween(payStart,payEnd);
        }

        if (!StringUtils.isEmpty(address)) {
            criteria.andPoAddressLike("%" + address + "%");
        }
        List<PositionInfoDO> list = positionInfoDOMapper.selectByExample(positionInfoDOExample);
        return list;
    }
}
